﻿using UnityEngine;
using System.Collections;

public class BrickNormalScript : MonoBehaviour {

	public AudioClip breakBrickSound;

	private Transform pieces;
	// Use this for initialization
	void Start () {
		pieces= this.transform.GetChild(0);

	}
	
	// Update is called once per frame
	void Update () {
	
	}

	void OnCollisionEnter2D(Collision2D collision) {
		Debug.Log(this.transform.position.y-collision.contacts[0].point.y);
		if((this.transform.position.y-collision.contacts[0].point.y)>=0.162){
			//change sprite
			Debug.Log(this.transform.position.y-collision.contacts[0].point.y);
			BreakBrickAnimation();
			//remove spire

			//play sound
			if (breakBrickSound!=null&&!Camera.current.audio.isPlaying) Camera.current.audio.PlayOneShot(breakBrickSound);
			this.renderer.enabled=false;
			this.collider2D.enabled=false;

		}
		
	}

	void BreakBrickAnimation(){
		pieces.gameObject.SetActive(true);

	}
}
